package com.ylbh.modules.member.controller;

import com.ylbh.common.exception.NormalException;
import com.ylbh.common.pojo.member.dto.BusinessAnalysisDTO;
import com.ylbh.common.utils.CommonResult;
import com.ylbh.common.utils.PageDTO;
import com.ylbh.common.utils.PageUtils;
import com.ylbh.common.utils.Ref;
import com.ylbh.modules.member.service.MembershipAnalysisService;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author: czx
 * @date: 2019/07/24 11:25
 * 会员分析
 */
@RestController
@RequestMapping("analysis")
public class MembershipAnalysisController {

    @Autowired
    private MembershipAnalysisService membershipAnalysisService;

    @GetMapping("queryMembershipActivityList")
//    @RequiresPermissions("analysis:queryMembershipActivityList")
    @ApiOperation("会员活跃度列表")
    public CommonResult<PageUtils> queryMembershipActivityList(BusinessAnalysisDTO businessAnalysisDTO) throws IOException {
        PageUtils list = membershipAnalysisService.queryMembershipActivityList(businessAnalysisDTO);
        return Ref.ok(list);
    }

    @GetMapping("membershipActivityListExcel")
    @ApiOperation("导出会员活跃度")
    public CommonResult membershipActivityListExcel(HttpServletRequest request, HttpServletResponse response) throws NormalException {
        membershipAnalysisService.membershipActivityListExcel(request, response);
        return Ref.ok();
    }

    @GetMapping("queryBusinessAnalysisList")
//    @RequiresPermissions("analysis:queryMembershipActivityList")
    @ApiOperation("联盟店消费信息列表")
    public CommonResult<PageUtils> queryBusinessAnalysisList(BusinessAnalysisDTO businessAnalysisDTO) {
        PageUtils list = membershipAnalysisService.queryBusinessAnalysisList(businessAnalysisDTO);
        return Ref.ok(list);
    }

    @GetMapping("orderAnalysisOfAllianceStores")
    @ApiOperation("联盟店订单分析导出")
    public CommonResult orderAnalysisOfAllianceStores(HttpServletRequest request, HttpServletResponse response) throws NormalException {
        membershipAnalysisService.orderAnalysisOfAllianceStores(request, response);
        return Ref.ok();
    }

    @GetMapping("queryGoodsAnalysisList")
//    @RequiresPermissions("analysis:queryMembershipActivityList")
    @ApiOperation("商城订单信息列表")
    public CommonResult<PageUtils> queryGoodsAnalysisList(BusinessAnalysisDTO businessAnalysisDTO) {
        PageUtils list = membershipAnalysisService.queryGoodsAnalysisList(businessAnalysisDTO);
        return Ref.ok(list);
    }

    @GetMapping("orderAnalysisOfMallExcel")
    @ApiOperation("商城订单分析导出")
    public CommonResult orderAnalysisOfMallExcel(HttpServletRequest request, HttpServletResponse response) throws NormalException {
        membershipAnalysisService.orderAnalysisOfMallExcel(request, response);
        return Ref.ok();
    }
}

